package com.dc.business.datacollectbusiness.controller;

import com.dc.business.datacollectbusiness.entity.Factories;
import com.dc.business.datacollectbusiness.entity.WorkShop;
import com.dc.business.datacollectbusiness.model.Result;
import com.dc.business.datacollectbusiness.service.WorkShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/workshop")
public class WorkShopController {
    @Autowired
    private WorkShopService workShopService;
    @GetMapping("seletebyid")
    public Result getAllWorkShopByFactoryId(@RequestParam Integer factoryId) {
        List<WorkShop> workShopList=workShopService.getAllWorkShopsByFactoryId(factoryId);
        if (workShopList.isEmpty()){
            return Result.error("workshop not found");
        }else {
            return Result.success(workShopList);
        }
    }

    @PostMapping("/insert")
    public Result insertWorkShop(@RequestBody WorkShop workShop) {
        boolean b=false;
        b=workShopService.insertWorkShops(workShop);
        if(b!=false){
            return Result.success(b);
        }else {
            return Result.error("插入失败");
        }
    }

    @DeleteMapping("/delete")
    public Result deleteWorkShop(@RequestParam int workShopId) {
        boolean b=false;
        b=workShopService.deleteWorkShopsById(workShopId);
        if(b!=false){
            return Result.success(b);
        }else {
            return Result.error("删除失败");
        }
    }

    @PostMapping("/update")
    public Result updateWorkShop(@RequestBody WorkShop workShop) {
        boolean b=false;
        b=workShopService.updateWorkShops(workShop);
        if(b!=false){
            return Result.success(b);
        }else {
            return Result.error("修改失败");
        }
    }
}
